package br.com.sysprova.controller;

import br.com.sysprova.model.HttpRestUtil;
import br.com.sysprova.model.bean.Aluno;
import br.com.sysprova.model.bean.Disciplina;
import br.com.sysprova.model.bean.Professor;
import br.com.sysprova.model.bean.Usuario;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class DisciplinaController {

	private Criptografia cript;
	
	private Disciplina disciplina;

	private HttpRestUtil httpRestUtil;

	private String URL_DISCIPLINA = "http://127.0.0.1:8080/SysProvasWS/ws/disciplina";


	private String URL_SALVAR = URL_DISCIPLINA+"/salvar";
	

	private String URL_GET = URL_DISCIPLINA;
	
	private String TYPE_JSON="application/json";

	public DisciplinaController() {
		httpRestUtil = HttpRestUtil.getHttpRestUtil();
		cript = Criptografia.getInstance();
	}

	public boolean salvar(String nome, String semestre, Professor professor) {
		try {
			Gson gsonConverter = new GsonBuilder().create();
			disciplina = new Disciplina();
			disciplina.setNome(nome);
			disciplina.setSemestre(semestre);
			disciplina.setProfessor(professor);
			httpRestUtil.enviaDadosWS(URL_SALVAR, "POST", TYPE_JSON,
					gsonConverter.toJson(disciplina).getBytes());
			return true;
		} catch (Exception e) {
			return false;
		}

	}
	
}
